package com.csea.app.controller;

import com.csea.app.model.vo.auth.LoginReqVO;
import com.csea.app.model.vo.auth.LoginRspVO;
import com.csea.app.model.vo.auth.RegisterReqVO;
import com.csea.app.service.UserAccountService;
import com.csea.common.aspect.ApiOperationLog;
import com.csea.common.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app/user/auth")
@Tag(name = "用户认证")
public class UserAuthController {

    @Autowired
    private UserAccountService userAccountService;

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    @ApiOperationLog(description = "用户登录操作")
    public Response<LoginRspVO> login(@RequestBody @Validated LoginReqVO reqVO) {
        return userAccountService.login(reqVO);
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    @ApiOperationLog(description = "用户注册操作")
    public Response<String> register(@RequestBody @Validated RegisterReqVO reqVO) {
        return userAccountService.register(reqVO);
    }

    @PostMapping("/logout")
    @Operation(summary = "用户登出")
    @ApiOperationLog(description = "用户登出操作")
    public Response<String> logout() {
        return userAccountService.logout();
    }
}